'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const Banners = app.model.define('Banners', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER
    },
    cover: {
      allowNull: false,
      type: Sequelize.STRING,
    },
    pathname: {
      allowNull: false,
      type: Sequelize.STRING,
      defaultValue: ''
    },
    click: {
      allowNull: false,
      type: Sequelize.INTEGER(8),
      defaultValue: '0'
    },
    remark: {
      allowNull: false,
      type: Sequelize.STRING
    },
    appId: {
      allowNull: false,
      type: Sequelize.STRING(100),
      defaultValue: ''
    },
    status: {
      allowNull: false,
      type: Sequelize.INTEGER(1),
      defaultValue: '0'
    },
    type: {
      allowNull: false,
      type: Sequelize.INTEGER(1),
      defaultValue: '0'
    },
    goodsId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      defaultValue: '0',
    },
    startedAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return this.getDataValue('startedAt') ? moment(this.getDataValue('startedAt')).format('YYYY-MM-DD HH:mm:ss') : '' }
    },
    endAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return this.getDataValue('endAt') ? moment(this.getDataValue('endAt')).format('YYYY-MM-DD HH:mm:ss') : '' }
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') }
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') }
    },
    deletedAt: {
      type: Sequelize.DATE
    }
  }, {
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    comment: '广告表'
  });

  return Banners;

};